use std::any::{Any, TypeId};
use log::info;

trait Animal: Any {
    fn speak(&self);
}

trait Mammal: Animal {
    fn walk(&self);
}

trait Canine: Mammal {
    fn bark(&self);
}

struct Dog;

impl Animal for Dog {
    fn speak(&self) {
        info!("Animal speak");
    }
}

impl Mammal for Dog {
    fn walk(&self) {
        info!("Mammal walk");
    }
}

impl Canine for Dog {
    fn bark(&self) {
        info!("Canine bark");
    }
}

fn check_trait<T: ?Sized + Any>() -> TypeId {
    TypeId::of::<T>()
}

#[test]
fn main() {
    let dog = Dog;

    // 检查具体类型
    info!("Is Dog: {}", (&dog as &dyn Any).is::<Dog>());

    // 检查 trait 对象类型
    let animal: &dyn Animal = &dog;
    info!("TypeId of dyn Animal: {:?}", check_trait::<dyn Animal>());
    info!("TypeId of dyn Mammal: {:?}", check_trait::<dyn Mammal>());
    info!("TypeId of dyn Canine: {:?}", check_trait::<dyn Canine>());
}